﻿var abp = abp || {};
(function ($) {

    /* DEFAULTS *************************************************/

    abp.libs = abp.libs || {};

    /* MESSAGE **************************************************/

    var showMessage = function (type, message, title) {
        if (!title) {
        	title = type;
            message = message;
        }

        return $.messager.alert(title, message, type);
    };

    abp.message.info = function (message, title) {
        return showMessage('info', message, title);
    };

    abp.message.success = function (message, title) {
        return showMessage('success', message, title);
    };

    abp.message.warn = function (message, title) {
    	return showMessage('warning', message, title);
    };

    abp.message.error = function (message, title) {
        return showMessage('error', message, title);
    };

    abp.message.confirm = function (message, titleOrCallback, callback) {
    	var userOpts = {
            text: message
        };

        if ($.isFunction(titleOrCallback)) {
            callback = titleOrCallback;
        } else if (titleOrCallback) {
            userOpts.title = titleOrCallback;
        };

		return $.Deferred(function($dfd) {
			$.messager.prompt(userOpts.title, userOpts.text, function (isConfirmed) {
    			callback && callback(isConfirmed);
                $dfd.resolve(isConfirmed);
    		});
        });
    };

})(jQuery);